{% extends "olexam/base.html" %}

{% load exam_extras %}

{% block content %}
    <h2>考试结果: {{ exam.title }}</h2>
    <div class="card mb-4">
        <div class="card-body">
            <h5 class="card-title">成绩摘要</h5>
            <p>得分: <strong>{{ attempt.total_score }} / {{ exam.total_score }}</strong></p>
            <p>状态: <span class="badge bg-{% if attempt.total_score >= exam.passing_score %}success{% else %}danger{% endif %}">
                {% if attempt.total_score >= exam.passing_score %}通过{% else %}未通过{% endif %}
            </span></p>
            <p>开始时间: {{ attempt.start_time|date:"Y-m-d H:i" }}</p>
            <p>提交时间: {{ attempt.submit_time|date:"Y-m-d H:i" }}</p>
        </div>
    </div>
    
    <h4>详细解答</h4>
    {% for response in responses %}
        <div class="question-card mb-3 {% if response.score == response.question.score %}border-success{% elif response.score > 0 %}border-warning{% else %}border-danger{% endif %}">
            <h5>问题 {{ forloop.counter }} ({{ response.question.get_type_display }}) - 
                得分: {{ response.score|default:0 }} / {{ response.question.score }}</h5>
            <p>{{ response.question.content }}</p>
            
            <div class="card mb-2">
                <div class="card-header bg-light">你的回答</div>
                <div class="card-body">
                    {% if response.question.type == 'true_false' %}
                        <p>{{ response.response_data|yesno:"正确,错误" }}</p>
                        <p class="text-muted">正确答案: {{ response.question_type.correct_answer|yesno:"正确,错误" }}</p>
                    
                    {% elif response.question.type == 'single_choice' %}
                        <p>{{ response.question_type.get_options|get_item:response.response_data }}</p>
                        <p class="text-muted">正确答案: {{ response.question_type.get_options|get_item:response.question_type.correct_option }}</p>
                    
                    {% elif response.question.type == 'multiple_choice' %}
                        <ul>
                            {% for index in response.response_data %}
                                <li>{{ response.question_type.get_options|get_item:index }}</li>
                            {% endfor %}
                        </ul>
                        <p class="text-muted">正确答案: 
                            {% for index in response.question_type.get_correct_options %}
                                {{ response.question_type.get_options|get_item:index }}{% if not forloop.last %}, {% endif %}
                            {% endfor %}
                        </p>
                    
                    {% elif response.question.type == 'programming' %}
                        <pre>{{ response.response_data }}</pre>
                        {% if response.execution_result %}
                            <h6>测试结果:</h6>
                            <pre>{{ response.execution_result.execution_output }}</pre>
                        {% endif %}
                    {% endif %}
                </div>
            </div>
            
            {% if response.feedback %}
                <div class="alert alert-info">
                    <strong>反馈:</strong> {{ response.feedback }}
                </div>
            {% endif %}
        </div>
    {% endfor %}
    
    <a href="{% url 'exam_list' %}" class="btn btn-primary">返回考试列表</a>
{% endblock %}
